package agents;

import java.util.ArrayList;
import java.util.HashMap;
import negotiator.Bid;
import negotiator.issue.Issue;
import negotiator.utility.UtilitySpace;

/**
 *
 * @author Oliver Trinnes, Thomas Nowicki, Felix Remmel, Ruben Schwarzwald
 */
public class FrequencyMap
{
  private UtilitySpace utilitySpace;
  private HashMap<IssueValue, Double> map;

  public FrequencyMap(UtilitySpace utilitySpace)
  {
    this.utilitySpace = utilitySpace;
    map = new HashMap<IssueValue, Double>();
  }

  public void addBid(Bid bid)
  {
    ArrayList<Issue> issues = utilitySpace.getDomain().getIssues();
    for(Issue issue : issues)
    {
      IssueValue issueValue = new IssueValue(issue, bid);
      Double amount = map.get(issueValue);
      if(amount == null)
        amount = 0.0;
      map.put(issueValue, amount+Math.pow(AgentFeruthol.ETA, amount));
    }
  }
  
  public double getFrequency(Bid bid)
  {
    double frequency = 0;
    ArrayList<Issue> issues = utilitySpace.getDomain().getIssues();
    for(Issue issue : issues)
    {
      IssueValue issueValue = new IssueValue(issue, bid);
      Double amount = map.get(issueValue);
      if(amount != null)
        frequency += amount;
    }
    return frequency;
  }

}
